/*
*
* 缺面正方体的缓冲区绘制
* r: 半边长
*
 */
function LackCube_bufferInit(gl, r=1) {

    const positions = [
        //front
        r, r, r,
        r, -r, r,
        -r, -r, r,
        -r, r, r,

        //back
        r, r, -r,
        r, -r, -r,
        -r, -r, -r,
        -r, r, -r,

        //left
        // -r, r, r,
        // -r, r, -r,
        // -r, -r, -r,
        // -r, -r, r,

        //right
        r, r, r,
        r, r, -r,
        r, -r, -r,
        r, -r, r,

        //up
        r, r, r,
        r, r, -r,
        -r, r, -r,
        -r, r, r,

        //down
        r, -r, r,
        r, -r, -r,
        -r, -r, -r,
        -r, -r, r
    ];

    const positionBuf = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, positionBuf);
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);

    //创建法矢

    const normals = [
        0, 0, 1,
        0, 0, 1,
        0, 0, 1,
        0, 0, 1,

        0, 0, -1,
        0, 0, -1,
        0, 0, -1,
        0, 0, -1,

        // -1, 0, 0,
        // -1, 0, 0,
        // -1, 0, 0,
        // -1, 0, 0,

        1, 0, 0,
        1, 0, 0,
        1, 0, 0,
        1, 0, 0,

        0, 1, 0,
        0, 1, 0,
        0, 1, 0,
        0, 1, 0,

        0, -1, 0,
        0, -1, 0,
        0, -1, 0,
        0, -1, 0,
    ];

    const verticeNormalBuf = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, verticeNormalBuf);
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(normals), gl.STATIC_DRAW);

    //创建颜色
    const colors = [
        [0.3, 0.5, 0.7, 1.0],
        [0.2, 0.6, 1.0, 1.0],
        // [0.6, 0.8, 0.1, 1.0],
        [0.9, 0.2, 0.4, 1.0],
        [0.4, 0.7, 0.1, 1.0],
        [0.9, 0.3, 0.7, 1.0],
    ];

    var faceColors = [];

    for (var i = 0; i < 5; i++) {
        var color = colors[i];
        for (var j = 0; j < 4; j++) {
            faceColors = faceColors.concat(color);
        }
    }

    const colorBuf = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, colorBuf);
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(faceColors), gl.STATIC_DRAW);

    const surfaces = [
        0, 1, 2,    0, 2, 3,
        4, 5, 6,    4, 6, 7,
        8, 9, 10,   8, 10, 11,
        12, 13, 14, 12, 14, 15,
        16, 17, 18, 16, 18, 19,
        // 20, 21, 22, 20, 22, 23,
    ];

    const surfaceBuf = gl.createBuffer();
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, surfaceBuf);
    gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(surfaces), gl.STATIC_DRAW);

    return {
        position: positionBuf,
        color: colorBuf,
        surface: surfaceBuf,
        normal: verticeNormalBuf,
        drawmode: gl.TRIANGLES,
        drawcount: 30,
        transparent: false,
    };

}